package org.example.bigwork.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.bigwork.DTO.LoginDTO;
import org.example.bigwork.common.Result;
import org.example.bigwork.entity.Student;
import org.example.bigwork.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public Result<LoginDTO> login(@RequestBody Student student) {
        Student login = userService.login(student);
        log.info("用户登录成功");
        LoginDTO loginDTO = LoginDTO.builder()
                .studentId(login.getStudentId())
                .name(login.getName())
                .build();

        return Result.success(loginDTO);
    }
}
